<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组方法</title>
    <script>
        let array = [5, 12, 8, 130, 44];
        console.log(array.at(2), array.at(-2));//正数为索引值下标，负数为倒数第几个
        let array1 = ['a', 'b', 'c'];
        let array2 = ['d', 'e', 'f'];
        let array3 = array1.concat(array2);
        console.log(array3);
        //console.log(array3.copyWithin(0, 2, 5))//将下标从2到4（不包括4）从0开始赋值
        console.log(array3.copyWithin(1, 4))//将下标从4到最后，从1开始赋值

        const array4 = ['a', 'b', 'c'];
        const iterator1 = array4.entries();
        console.log(iterator1.next().value);// 顺序输出每一个值及其下标     
        console.log(iterator1.next().value);
        console.log(iterator1.next().value);

        const isBelowThreshold = (currentValue) => currentValue < 40;
        const array5 = [1, 30, 39, 29, 10, 13];
        console.log(array5.every(isBelowThreshold));//查看数组中每个值是否符合函数要求

        const array6 = [1, 2, 3, 4];
        console.log(array6.fill(0, 2, 4));// 从下标2到4全赋值为0
        console.log(array6.fill(5, 1));//从下标1开始全赋值为5
        console.log(array6.fill(6));//全赋值为6

        const words = ['spray', 'elite', 'exuberant', 'destruction', 'present'];
        const result = words.filter((word) => word.length > 6);//将符合条件的留下其余删去
        console.log(result);

        const array7 = [5, 12, 8, 130, 44];
        const found = array7.find((element) => element > 10);//返回第一个符合条件的值
        console.log(found);

        const isLargeNumber = (element) => element >= 12;
        console.log(array7.findIndex(isLargeNumber));//返回第一个符合条件值的下标

        const found2 = array7.findLast((element) => element > 45);
        //findLast()与find()类似，返回最后一个符合条件的值
        console.log(found2);

        console.log(array1.findLastIndex(isLargeNumber));
        //findLastIndex()与findIndex()类似，返回最后一个符合条件值的下标

        const array8 = ['a', 'b', 'c'];
        const iterator2 = array8[Symbol.iterator](); 
        for (const value of iterator2) {
            console.log(value);
        }
    </script>
</head>

<body>

</body>

</html>